<?php

namespace app\common\model;

use think\Model;


class Invoice extends Model
{

    

    

    // 表名
    protected $name = 'invoice';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
		'type_text',
	    'status_text'
    ];
    
	const TYPE_C = 1;
	const TYPE_P = 2;
	
	public static $typeList = [
		self::TYPE_C => '公司',
		self::TYPE_P => '个人',
	];
    
	public function getTypeTextAttr($value, $data) {
		$value = $value ? : $data['type'];
		$list = self::$typeList;
		return $list[$value] ??'';
	}
	
	
	const STATUS_W = 0;
	const STATUS_Y = 1;
	
	public static $statusList = [
		self::STATUS_Y => '已开票',
		self::STATUS_W => '待开票',
	];
	
	public function getStatusTextAttr($value, $data) {
		$value = $value ? : $data['status'];
		$list = self::$statusList;
		return $list[$value] ??'';
	}

	public function user() {
		return $this->belongsTo('user', 'user_id', 'id', '', 'left')->setEagerlyType(0);
	}

	public function order() {
		return $this->belongsTo('order', 'order_id', 'id', '', 'left')->setEagerlyType(0);
	}
}
